﻿/// <summary>
/// Author: Le Van Binh
/// Date: 2013/06/06
/// </summary>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Threading;
using System.Globalization;
using Ivs.Core.Common.Utilities;

namespace SketchTour
{
    public class BaseController : Controller
    {
        #region Public Const
        // Set language is English
        public const string m_English = "en-US";
        //Set language is Japanese
        public const string m_Japanese = "ja-JP";
        #endregion

        #region OnActionExecuting

        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            
        }

        #endregion

        #region Method
        /// <summary>
        /// Manage the internationalization before to invokes the action in the current controller context.
        /// </summary>
        /// @cond
        /// @Author : Le Van Binh
        /// @endcond
        protected override void ExecuteCore()
        {
            //Create list data for dropdownlist
            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            dictionary.Add(m_English, "English");
            dictionary.Add(m_Japanese, "Japanese");
            //Set default language is English
            int culture = 0;
            //Check Status Language
            if (this.Session == null || this.Session["CurrentCulture"] == null || Utilities.parseInt(Session["CurrentCulture"]) == 0)
            {
                int.TryParse(System.Configuration.ConfigurationManager.AppSettings["Culture"], out culture);
                this.Session["CurrentCulture"] = culture;
                ViewBag.ddpLanguage = new SelectList(dictionary, "Key", "Value", m_English);
                // Set the thread's CurrentCulture the same as CurrentUICulture.
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(m_English);
            }
            else
            {
                culture = Utilities.parseInt(this.Session["CurrentCulture"]);
                //Set Japanese language in case japanese
                // Set the thread's CurrentCulture the same as CurrentUICulture.
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(m_Japanese);
                ViewBag.ddpLanguage = new SelectList(dictionary, "Key", "Value", Session["Language"].ToString());
            }
            SessionManager.CurrentCulture = culture;     
            // Invokes the action in the current controller context.
            base.ExecuteCore();
        }

        protected override bool DisableAsyncSupport
        {
            get { return true; }
        }
        #endregion
    }
}